Cast in java means to convert a value from one type to a different type.
for example: assuming that x is a double. you can do x = (int)(x + 0.5); to round a double to integer.
Cast is very useful in ArrayList, because ArrayList save all value as Object type, therefore, every time you try to get something from ArrayList, you have to cast it.
- for example: assuming that x is a double. you can do x = (int)(x + 0.5); to round a double to integer.
Cast is very useful in ArrayList, because ArrayList save all value as Object type, therefore, every time you try to get something from ArrayList, you have to cast it.